package com.xteam.ecsystem.contorller;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.tangkf.utils.bean.ReqHelper;
import com.xteam.ecsystem.service.admin.MessageService;
import com.xteam.ecsystem.service.admin.SystemLogService;
import com.xteam.ecsystem.utils.ConstantLocation;

@Controller
public class MessageContorller {
	
	@Autowired
	private MessageService messageservice;
	
	@Autowired
	private SystemLogService logService;

	@RequestMapping("/getMessageList.do")
	public void getMessageList(HttpServletRequest request,
			HttpServletResponse response, ModelMap modelMap) throws IOException {
		int pageIndex = ReqHelper.getRequestInt(request, "pageIndex");
		int pageSize = ReqHelper.getRequestInt(request, "pageSize");
		String bumName = ReqHelper.getRequestString(request, "bumName");
		String bumType = ReqHelper.getRequestString(request, "bumType");
		String bumTitle = ReqHelper.getRequestString(request, "bumTitle");
		String bumState = ReqHelper.getRequestString(request, "bumState");
		String isreply = ReqHelper.getRequestString(request, "isreply");
		String strList = messageservice.getMessageList(pageIndex, pageSize,
				bumName, bumType, bumTitle, bumState, isreply);
		response.getWriter().write(strList);
	}

	@RequestMapping("/savereply.do")
	public void savereply(HttpServletRequest request,
			HttpServletResponse response, ModelMap modelMap) throws IOException {
		String bumId = ReqHelper.getRequestString(request, "bumId");
		String reply = ReqHelper.getRequestString(request, "reply");
		String lslUser = ReqHelper.getRequestString(request, "lslUser");
		String lslAddress = ReqHelper.getRequestString(request, "lslAddress");
		
		messageservice.savereply(lslUser, "", bumId, reply, lslAddress);
		
		this.logService.saveSystemLogs(lslUser, lslAddress, ConstantLocation.LOG_MEMBERMSG_MGR, 
				"savereply", ConstantLocation.LOG_REPLYMSG, "BaseReplyInfo");
	}

	@RequestMapping("/saveApprove.do")
	public void saveApprove(HttpServletRequest request,
			HttpServletResponse response, ModelMap modelMap) throws IOException {
		String bumId = ReqHelper.getRequestString(request, "bumId");
		String state = ReqHelper.getRequestString(request, "state");
		String lslUser = ReqHelper.getRequestString(request, "lslUser");
		String lslAddress = ReqHelper.getRequestString(request, "lslAddress");
		
		messageservice.saveApprove(bumId,state);
		
		this.logService.saveSystemLogs(lslUser, lslAddress, ConstantLocation.LOG_MEMBERMSG_MGR, 
				"saveApprove", ConstantLocation.LOG_Edit_STATE, "BaseUserMessage");
	}

	@RequestMapping("/delMessage.do")
	public void delMessage(HttpServletRequest request,
			HttpServletResponse response, ModelMap modelMap) throws IOException {
		String bumId = ReqHelper.getRequestString(request, "bmbIdlist");
		String lslUser = ReqHelper.getRequestString(request, "lslUser");
		String lslAddress = ReqHelper.getRequestString(request, "lslAddress");
		
		messageservice.delMessage(bumId);
		
		this.logService.saveSystemLogs(lslUser, lslAddress, ConstantLocation.LOG_MEMBERMSG_MGR, 
				"delMessage", ConstantLocation.LOG_DELETE, "BaseUserMessage");
	}

	@RequestMapping("/findMessageReply.do")
	public void findMessageReply(HttpServletRequest request,
			HttpServletResponse response, ModelMap modelMap) throws IOException {
		String bumId = ReqHelper.getRequestString(request, "bumId");
		response.getWriter().write(messageservice.findMessageReply(bumId));
	}

	@RequestMapping("/deleteReply.do")
	public void deleteReply(HttpServletRequest request,
			HttpServletResponse response, ModelMap modelMap) throws IOException {
		String briId = ReqHelper.getRequestString(request, "briId");
		String lslUser = ReqHelper.getRequestString(request, "lslUser");
		String lslAddress = ReqHelper.getRequestString(request, "lslAddress");
		
		messageservice.deleteReply(briId);
		
		this.logService.saveSystemLogs(lslUser, lslAddress, ConstantLocation.LOG_MEMBERMSG_MGR, 
				"deleteReply", ConstantLocation.LOG_DELETE_REPLY, "BaseReplyInfo");
	}

	@RequestMapping("/updateReply.do")
	public void updateReply(HttpServletRequest request,
			HttpServletResponse response, ModelMap modelMap) throws IOException {
		String briId = ReqHelper.getRequestString(request, "briId");
		String briContent = ReqHelper.getRequestString(request, "briContent");
		String lslUser = ReqHelper.getRequestString(request, "lslUser");
		String lslAddress = ReqHelper.getRequestString(request, "lslAddress");
		
		messageservice.updateReply(briId,briContent);
		
		this.logService.saveSystemLogs(lslUser, lslAddress, ConstantLocation.LOG_MEMBERMSG_MGR, 
				"updateReply", ConstantLocation.LOG_MODIFY_REPLY, "BaseReplyInfo");
	}
}
